package org.example;

/**
 * Author:qqw
 * Date:2024-06-18
 * Description:服务Ip端口枚举
 */
public enum ServiceHostPortEnum {

    LISTEN("","127.0.0.1",31880),
    HEARTBEAT("","192.168.2.87",8848),
    ADMIN("com.weihuang.ums.admin","192.168.2.87",31884),
    ADMIN_SERVER("ums-admin","192.168.2.87",31884),
    BMS("com.weihuang.ums.bms","192.168.2.87",31881),
    BMS_SERVER("ums-bms","192.168.2.87",31881),
    WMS("com.weihuang.ums.wms","192.168.2.87",31882),
    WMS_SERVER("ums-wms","192.168.2.87",31882),
    OMS("com.weihuang.ums.oms","192.168.2.87",31883),
    OMS_SERVER("ums-oms","192.168.2.87",31883),
    RMS("com.weihuang.ums.rms","192.168.2.87",31888),
    RMS_SERVER("ums-rms","192.168.2.87",31888),
    AUTH("com.weihuang.ums.auth","192.168.2.87",31885),
    AUTH_SERVER("ums-auth","192.168.2.87",31885),
    LOG("com.weihuang.ums.log","192.168.2.87",31886),
    LOG_SERVER("ums-log","192.168.2.87",31886),
    DISPATCHER("com.weihuang.ums.dispatcher","192.168.2.87",31887),
    DISPATCHER_SERVER("ums-dispatcher","192.168.2.87",31887),
    ;

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    private String service;

    private String ip;

    private Integer port;

    ServiceHostPortEnum(String service,String ip,Integer port){
        this.service = service;
        this.ip = ip;
        this.port = port;
    }

    public static Integer getPortByService(String service){
        ServiceHostPortEnum[] values = ServiceHostPortEnum.values();
        for (ServiceHostPortEnum value : values) {
            if(value.service.equals(service)){
                return value.port;
            }
        }
        return HEARTBEAT.port;
    }

    public static ServiceHostPortEnum getByService(String service){
        ServiceHostPortEnum[] values = ServiceHostPortEnum.values();
        for (ServiceHostPortEnum value : values) {
            if(value.service.equals(service)){
                return value;
            }
        }
        return HEARTBEAT;
    }

    public static String[] getServiceArr(){
        ServiceHostPortEnum[] values = ServiceHostPortEnum.values();
        String[] arr = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            arr[i] = values[i].service;
        }
        return arr;
    }

    public static String[] getServiceArrNonHeartBeat(){
        ServiceHostPortEnum[] values = ServiceHostPortEnum.values();
        String[] arr = new String[values.length-1];
        for (int i = 1; i < values.length; i++) {
            arr[i-1] = values[i].service;
        }
        return arr;
    }
}
